﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_User_KetQuaTimKiemMauBieu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layDanhSachMauBieuDaDuyet();
        }
    }
    protected void btnTimKiem_Click(object sender, EventArgs e)
    {
        //Xoa ket qua da hien thi tren gv truoc do
        gvDanhSachMauBieu.DataSource = null;
        gvDanhSachMauBieu.DataBind();
        
        //
        if (rdoTimTheoNoiDungMauBieu.Checked)
        {
            layDanhSachMauBieuDaDuyetTheoNoiDungMauBieu();
        }

        if (rdoTimTheoTenFileMauBieu.Checked)
        {
            layDanhSachMauBieuDaDuyetTheoTenFileMauBieu();
        }
    }
    protected void gvDanhSachMauBieu_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvDanhSachMauBieu.PageIndex = e.NewPageIndex;

        if (rdoTimTheoNoiDungMauBieu.Checked)
        {
            layDanhSachMauBieuDaDuyetTheoNoiDungMauBieu();
        }

        if (rdoTimTheoTenFileMauBieu.Checked)
        {
            layDanhSachMauBieuDaDuyetTheoTenFileMauBieu();
        }

        if (rdoTimTheoNoiDungMauBieu.Checked == false && rdoTimTheoTenFileMauBieu.Checked == false)
        {
            layDanhSachMauBieuDaDuyet();
        }
    }
    protected void layDanhSachMauBieuDaDuyetTheoNoiDungMauBieu()
    {
        MauBieu mbDTO = new MauBieu();
        mbDTO.NoiDungMauBieu = txtTimTheoNoiDungMauBieu.Text;

        MauBieuBUS mbBUS = new MauBieuBUS();
        gvDanhSachMauBieu.DataSource = mbBUS.layDanhSachMauBieuDaDuyetTheoNoiDungMauBieu(mbDTO);
        gvDanhSachMauBieu.DataBind();
    }
    protected void layDanhSachMauBieuDaDuyetTheoTenFileMauBieu()
    {
        MauBieu mbDTO = new MauBieu();
        mbDTO.TenFileMauBieu = txtTimTheoTenFileMauBieu.Text;

        MauBieuBUS mbBUS = new MauBieuBUS();
        gvDanhSachMauBieu.DataSource = mbBUS.layDanhSachMauBieuDaDuyetTheoTenFileMauBieu(mbDTO);
        gvDanhSachMauBieu.DataBind();
    }
    protected void layDanhSachMauBieuDaDuyet()
    {
        MauBieuBUS mbBUS = new MauBieuBUS();
        gvDanhSachMauBieu.DataSource = mbBUS.layDanhSachMauBieuDaDuyet();
        gvDanhSachMauBieu.DataBind();
    }
    protected void btnLoadTatCaMauBieu_Click(object sender, EventArgs e)
    {
        if (rdoTimTheoNoiDungMauBieu.Checked)
        {
            rdoTimTheoNoiDungMauBieu.Checked = false;
        }

        if (rdoTimTheoTenFileMauBieu.Checked)
        {
            rdoTimTheoTenFileMauBieu.Checked = false;
        }

        txtTimTheoNoiDungMauBieu.Text = string.Empty;
        txtTimTheoTenFileMauBieu.Text = string.Empty;
        
        layDanhSachMauBieuDaDuyet();
    }
}